#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

typedef struct {int v,w,nxt;}edge;

int f[MAXN],h[MAXN],n,s,cnt;
edge e[MAXN<<1];
bool isleaf[MAXN];

void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void dfs(int x,int p){
	isleaf[x] = 1;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		dfs(y,x);isleaf[x] = 0;
		if(isleaf[y]) f[x] += e[i].w;
		else f[x] += min(e[i].w,f[y]);
	}
}

int main (){
	scanf("%d %d",&n,&s);
	for(int i = 1;i < n;i++){
		int a,b,c;scanf("%d %d %d",&a,&b,&c);
		link(a,b,c);link(b,a,c);
	}
	dfs(s,0);
	printf("%d\n",f[s]);
	return 0;
}
